﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Temp.Database;
using Temp.Model;

namespace Temp.Controller
{
    class ExitController
    {
        private SQLiteFactory sqlf;
        private List<Exit> exitList;
        private SQLite.SQLiteConnection conn;
        public ExitController() {
            sqlf = new SQLiteFactory();
        }

        public List<Exit> getExits(int idPlace) {
            conn = sqlf.getConnection();
            exitList = (conn.Table<Exit>().Where(e => e.idPlace == idPlace)).ToList();
            conn.Close();
            return exitList;
        }
        public Exit getExit(int idPlace, String dir)
        {
            Exit exit = new Exit();
            conn = sqlf.getConnection();
            if (dir.Equals("north"))
                dir = "south";
            else if (dir.Equals("south"))
                dir = "north";
            else if (dir.Equals("west"))
                dir = "east";
            else if (dir.Equals("east"))
                dir = "west";


            exit = conn.Query<Exit>("Select * from Exit where idPlace=" + idPlace + " and direction = '" + dir + "'").ToList()[0];
            conn.Close();
            return exit;
        }

        public List<Rectangle> allExitRect(int idPlace)
        {
            List<Exit> listexit = getExits(idPlace);
            List<Rectangle> rects = new List<Rectangle>();

            for (int i = 0; i < listexit.Count; i++)
                rects.Add(new Rectangle(listexit.ElementAt(i).endX, listexit.ElementAt(i).endY,
                   listexit.ElementAt(i).dimX, listexit.ElementAt(i).dimY)); //temporary size

            return rects;
        }

    }
}
